package com.company.装饰模式;

public class Test2 {
    public static void test2(Person2 person2){
        person2.work2();
    }

    public static void main(String[] args) {
        Person2 person2 = new EatDecorator(new Worker());
        test2(person2);
    }

}
interface Person2{
    public void work2();
}
class Worker implements Person2{
    @Override
    public void work2() {
        System.out.println("工人在上班");
    }
}
abstract class Decorator2 implements Person2{
    protected Person2 person2;
    public Decorator2(Person2 person2){
        this.person2=person2;
    }
}
class EatDecorator extends Decorator2{
    public EatDecorator(Person2 person2){
        super(person2);
    }
    @Override
    public void work2() {
        System.out.print("爱吃米饭");
        this.person2.work2();
    }
}
